<?php

if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Hdoilsubsidycitymodel extends CI_Model {

	protected $_CI;

	public static $searchField = array(
		'city_status' => 'city_status',
	);
	public static $likeField = array();
	public static $sortField = array();

	public function __construct(){
		parent::__construct();
		$this->_CI = & get_instance();
	}
/*
| -------------------------------------------------------------------
|  GET Functions
| -------------------------------------------------------------------
*/
	public function getCityListSection($assist = array()){
		$this->db->from('hd_oil_subsidy_city');
		if(!empty($assist['where'])) $this->db->where($assist['where']);
		if(!empty($assist['like'])) $this->db->like($assist['like']);
		if(!empty($assist['where_in'])){
			foreach ($assist['where_in'] as $k => $v) {
				if(!empty($v) && is_array($v)) $this->db->where_in($k,$v);
				else {
					$query = $this->db->get();
					return array(array(),0);
				}
			}
		}
		if(!empty($assist['pagination'])) $count = $this->db->count_all_results('',SQL_EXECUTE_RETAIN_CONDITION);

		$this->db->order_by('city_id','asc');
		$query = $this->db->get();
		$list = $query->result_array();

		if(empty($assist['pagination'])) $count = count($list);

        return array($list,$count);
	}

	public function getActiveCityList() {
		$this->db->from('hd_oil_subsidy_city');
		$this->db->where('city_status',STATUS_ACTIVE);
		$query = $this->db->get();
		$list = $query->result_array();

		return $list;
	}

	public function getCity($city_id){
		$this->db->from('hd_oil_subsidy_city');
		$this->db->where('city_id',$city_id);
		$this->db->limit(1);
		$query = $this->db->get();
		$res = $query->row_array();

		return $res;
	}
/*
| -------------------------------------------------------------------
|  CREATE Functions
| -------------------------------------------------------------------
*/
	public function createCity($info){
		$this->db->insert('hd_oil_subsidy_city',$info);
		return $this->db->insert_id();
	}
/*
| -------------------------------------------------------------------
|  EDIT Functions
| -------------------------------------------------------------------
*/
	public function editCity($info){
		$this->db->where('city_id',$info['city_id']);
		$this->db->update('hd_oil_subsidy_city',$info);
	}
}